package de.hochschuletrier.bachelor.antfarm.control;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;

import de.hochschuletrier.bachelor.antfarm.settings.Settings;

public class SimulationController {
	
	public void update(GameContainer gc, int delta) {
		if (gc.getInput().isKeyPressed(Input.KEY_ADD)) {
			Settings.increaseCalculatedFramesPerSecond();
		}
		else if (gc.getInput().isKeyPressed(Input.KEY_SUBTRACT)) {
			Settings.decreaseCalculatedFramesPerSecond();
		}
		else if (gc.getInput().isKeyPressed(Input.KEY_SPACE)) {
			Settings.setCalculatedFramesPerSecond(0);
		}
		
		float transX = 0f, transY = 0f;
		if (gc.getInput().isKeyDown(Input.KEY_UP)) {
			transY += Settings.getTranslatePerSecond() * (delta / 1000f);
		}
		if (gc.getInput().isKeyDown(Input.KEY_DOWN)) {
			transY -= Settings.getTranslatePerSecond() * (delta / 1000f);
		}
		if (gc.getInput().isKeyDown(Input.KEY_RIGHT)) {
			transX -= Settings.getTranslatePerSecond() * (delta / 1000f);
		}
		if (gc.getInput().isKeyDown(Input.KEY_LEFT)) {
			transX += Settings.getTranslatePerSecond() * (delta / 1000f);
		}
		
		float scale = Settings.getScale();
		if (gc.getInput().isKeyPressed(Input.KEY_Q)) {
			scale *= 1.5f;
			//transX -= (gc.getWidth() / (scale * 2));
			//transY -= (gc.getHeight() / (scale * 2));
		}
		if (gc.getInput().isKeyPressed(Input.KEY_E)) {
			//transX += (gc.getWidth() / (scale * 2));
			//transY += (gc.getHeight() / (scale * 2));
			scale /= 1.5f;
		}
		Settings.setScale(scale);
		
		Settings.setTranslateX(Settings.getTranslateX() + transX);
		Settings.setTranslateY(Settings.getTranslateY() + transY);
	}
}
